package com.powernode.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class AppListener implements ServletContextListener {
    /**
     * tomcat启动时调用
     * @param servletContextEvent
     */
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        //得到ServletContext
        ServletContext context = servletContextEvent.getServletContext();
        //想context里面放项目部署的名字
        String contextPath = context.getContextPath();
        context.setAttribute("ctx",contextPath);
    }

    /**
     * tomcat关闭时调用
     * @param servletContextEvent
     */
    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
